<template>
	<view>
		<u-sticky><u-tabs :list="listType" :is-scroll="false" :current="current" @change="sectionChange"></u-tabs></u-sticky>
		<view v-if="current == 0">
			<u-table>
				<u-tr class="u-tr">
					<u-th class="u-th" width="70%">门店</u-th>
					<u-th class="u-th" width="15%">序号</u-th>
					<u-th class="u-th" width="15%">操作</u-th>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in dataList0" :key="index">
					<u-td class="u-td" width="70%">{{item.putGoodsName}}</u-td>
					<u-td class="u-td" width="15%"><text style="color: blue;" @click="showOrd(item)">{{item.ord}}</text></u-td>
					<u-td class="u-td" width="15%"><text style="color: red;" @click="noBind(item)">解绑</text></u-td>
				</u-tr>
			</u-table>
		</view>
		<view v-if="current == 1">
			<u-sticky>
				<view class=" u-p-r-30 u-p-l-30 margin-zdy">
					<u-input v-model="operateName" placeholder="选择项目" type="select" @click="getO()"/>
					<u-input v-model="setMentiontime" placeholder="选择日期" type="select" @click="getT()"/>
					<u-search placeholder="请输入关键词搜索" :clearabled="true" v-model="keyword" border-color="#606266" @custom="search" @search="search"></u-search>
				</view>
			</u-sticky>
			<u-table>
				<u-tr class="u-tr">
					<u-th class="u-th" width="80%">门店</u-th>
					<u-th class="u-th" width="20%">操作</u-th>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in dataList1" :key="index">
					<u-td class="u-td" width="80%">{{item.getUnit}}</u-td>
					<u-td class="u-td" width="20%"><text style="color: red;" @click="bind(item)">绑定</text></u-td>
				</u-tr>
			</u-table>
		</view>
		
		
		<view>
			<u-toast ref="uToast" />
		</view>
		<view>
			<u-calendar v-model="show8" mode="date" max-date="2070-01-01" @change="changesetMentiontime"></u-calendar>
		</view>
		<view>
			<u-select v-model="show2" :list="olist" @confirm="confirm"></u-select>
		</view>
		<u-popup v-model="isOrd" mode="center" width="500rpx" height="400rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">序号</view>
			<view class=" u-m-20">
				<u-input v-model="item.ord" type="digit" :border="true"
					placeholder="请输入序号" />
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="setOrd()">确定</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listType: [
					{
						name: '已绑定'
					}, 
					{
						name: '未绑定'
					}
				],
				dataList0:[],
				dataList1:[],
				current: 0,
				keyword:"",
				setMentiontime:'',
				operateId:'',
				operateName:'',
				item:{
					ord:1,
					id:'',
				},
				isOrd:false,
				show2:false,
				show8:false,
				olist:[],
			}
			
		},
		onLoad() {
			let year = new Date().getFullYear();//年
			let month = new Date().getMonth() + 1;//注意！月份是从0月开始获取的，所以要+1;
			let day = new Date().getDate();//日
			this.setMentiontime =  year + '-' + (month >= 10 ? month : '0' + month) + '-' + (day >= 10 ? day : '0' + day);
			
			this.$http.post('/rest/operate/findme',{
			},{
				params: {
				},
				header: {
					'Authorization' :uni.getStorageSync('token'),
				}
			}).then(res => {
				if(res.data.data != '' && res.data.data != null){
					this.operateId = res.data.data.id
					this.operateName = res.data.data.operateName
				}
			})
			
			this.$http.post('/rest/operate/list3',{
			},{
				params: {},
				header: {
					'Authorization' :uni.getStorageSync('token'),
				}
			}).then(res => {
				for(let item1 of res.data.data) {
					let obj = {}
					obj.value = item1.id
					obj.label = item1.operateName
					this.olist.push(obj)
				}
			})
		},
		onShow() {
			this.getDataList();
		},
		onPullDownRefresh() {
			this.getDataList()
			uni.stopPullDownRefresh()
		},
		methods: {
			showOrd(obj){
				this.item.id = obj.id,
				this.item.ord = obj.ord,
				this.isOrd = true;
			},
			setOrd(){
				this.$http.post('/rest/transportPlateStore/setOrd', {}, {
					params: {
						id:this.item.id,
						ord:this.item.ord,
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '操作成功',
							duration: 3000,
							type: 'success'
						})
						this.isOrd = false;
						this.getDataList();
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							duration: 3000,
							type: 'error'
						})
					}
				})
			},
			sectionChange(e){
				this.current = e
				this.getDataList();
			},
			confirm(e) {
				console.log(e);
				this.operateId = e[0].value
				this.operateName = e[0].label
				this.getDataList();
				// this.refresh()
			},
			getO(){
				this.show2 = true
			},
			changesetMentiontime(e) {
				this.setMentiontime = e.result
				this.getDataList();
				// this.refresh()
			},
			getT(){
				this.show8 = true
			},
			bind(item){
				this.$http.post('/rest/transportPlateStore/bind', {}, {
					params: {
						putGoodsId: item.xlbClientId,
						putGoodsName:item.getUnit,
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '操作成功',
							duration: 3000,
							type: 'success'
						})
						this.getDataList();
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							duration: 3000,
							type: 'error'
						})
					}
				})
			},
			noBind(item){
				this.$http.post('/rest/transportPlateStore/noBind', {}, {
					params: {
						id:item.id
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '操作成功',
							duration: 3000,
							type: 'success'
						})
						this.getDataList();
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							duration: 3000,
							type: 'error'
						})
					}
				})
			},
			getDataList(){
				uni.showLoading({
					title: '加载中...'
				})
				if(this.current == 0){
					this.$http.post('/rest/transportPlateStore/getBindList',{
					},{
						params: {},
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						this.dataList0 = res.data
					})
				} else if(this.current == 1){
					if(this.keyword == "" || this.keyword == null || this.operateId == "" || this.operateId == null){
						this.dataList = []
						this.totalVolume = ''
					} else {
						uni.showLoading({
							title: '加载中...'
						})
						this.$http.post('/rest/transportPlateStore/getNoBindList',{
						},{
							params: {
								setMentiontime:this.setMentiontime,
								getUnit:this.keyword,
								operateIdc:this.operateId
							},
							header: {
								'Authorization' :uni.getStorageSync('token'),
							}
						}).then(res => {
							uni.hideLoading()
							this.dataList1 = res.data.data
						})
					}
				}
				uni.hideLoading()
			},
			search(e){
				this.getDataList();
			}
		}
	
	}
</script>

<style lang="scss">
	.u-body-item {
		padding: 20rpx 15rpx;
	}
	.wrap {
		padding: 0rpx 12rpx;
	}

	.u-row {
		margin: 10rpx 2rpx;
	}
	.weikaishi2{
		font-size: 34rpx;
	}
	.baise{
		background-color: #2979ff;
		color: #ffffff;
		font-size: 34rpx;
	}
	.margin-zdy{
		padding: 5rpx 20rpx 5rpx 30rpx;
		background-color: #FFFFFF;
	}
	.jiange{
		border-bottom: 1px solid #ebebeb;
	}
</style>